package com.foreveross.service.impl;

import com.foreveross.domain.Product;
import com.foreveross.repository.ProductRepository;
import com.foreveross.security.domain.User;
import com.foreveross.security.service.rpc.api.UserService;
import com.foreveross.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2016/7/5.
 */
@Service("productService")
public class ProductServiceImpl implements ProductService{

    @Autowired
    private ProductRepository productRepository;

    @Autowired
    private UserService userService;

    public ProductServiceImpl(){}

    public ProductServiceImpl(ProductRepository productRepository,UserService userService){
        this.productRepository=productRepository;
        this.userService=userService;
    }

    @Override
    public Object getProductList() {
        return productRepository.findAll();
    }

    @Override
    public Object addProduct(Product product) {
        if(product!=null){
            productRepository.save(product);
            return true;
        }
        return false;
    }

    @Override
    public Object findUserByToken(String token) {
        User user= (User) userService.findByToken(token);
        return user;
    }
}
